#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cstring>

//dijkstra
using namespace std;
using PII = pair<int, int>;
const int N = 3010, M = 810;

int n, m, t;
int h[N], e[N], ne[N], w[N], idx;
int dist[810][810];
int state[810];
int pla[510];
int sum[810];

void dijkstra(int p){
    memset(state, 0, sizeof state);
    priority_queue<PII, vector<PII>, greater<PII>> que;
    dist[p][p] = 0;
    que.push({0, p});

    while(que.size()){
        PII temp = que.top();
        que.pop();

        int ver = temp.second, dis = temp.first;
        if(state[ver]) continue;

        state[ver] = true;

        for (int u = h[ver]; u != -1; u = ne[u]){
            int j = e[u];
            if(dist[p][j] > dis + w[u]){
                dist[p][j] = dis + w[u];
                que.push({dist[p][j], j});
            }
        }
    }
}

void add(int a, int b, int c){
    e[idx] = b;
    w[idx] = c;
    ne[idx] = h[a];
    h[a] = idx++;
}


int solve(){
    for (int i = 1; i <= m; i ++){
        dijkstra(i);
    }

    for (int i = 1; i <= m; i ++){
        for (int j = 1; j <= n; j ++){
            if(dist[i][pla[j]] == 0x3f3f3f3f){
                sum[i] = -1;
                break;
            }else{
                sum[i] += dist[i][pla[j]];
            }
        }
    }

    int minv = 1e9 + 10;
    for (int i = 1; i <= m; i ++){
        if(sum[i] == -1)continue;
        minv = min(minv, sum[i]);
    }

    return minv;
}


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);


    memset(dist, 0x3f, sizeof dist);
    memset(h, -1, sizeof h);

    cin >> n >> m >> t;
    for (int i = 1; i <= n; i ++){
        cin >> pla[i];
    }

    for (int i = 0; i < t; i ++){
        int a, b, c;
        cin >> a >> b >> c;
        add(a, b, c);
        add(b, a, c);
    }

    int res = solve();

    cout << res;
    return 0;
}